local actions = require('telescope.actions')
local telescope = require('telescope')

telescope.setup({
    defaults = {
        mappings = {
            i = {
                ['<esc>'] = actions.close,
                ['<C-u>'] = false,
            }
        }
    },
    pickers = {
        find_files = {
            theme = 'dropdown',
        },
        oldfiles = {
            theme = 'dropdown',
        },
        current_buffer_tags = {
            theme = 'dropdown',
        },
        lsp_document_symbols = {
            theme = 'dropdown',
        },
        lsp_workspace_symbols = {
            theme = 'dropdown',
        },
    },
    extensions = {
        tasks = {
            output = {
                style = 'float',   -- 'vsplit' | 'split' | 'float'
                layout = 'center', -- 'bottom' | 'left' | 'right' | 'center'
                scale = 0.4,       -- output window to editor size ratio
            },
            -- Directory to store the modified commands data to.
            -- Set it to false to disable saving modified commands.
            data_dir = false,
            -- other picker setup values
        },
    }
})

telescope.load_extension('dap')
telescope.load_extension('i23')

-- 快捷键
local bufopts = { noremap = true, silent = true }
local builtin = require('telescope.builtin')

vim.keymap.set('n', '<C-p>', builtin.find_files, bufopts)
vim.keymap.set('n', '<C-h>', builtin.oldfiles, bufopts)
vim.keymap.set('n', '<C-t>', builtin.lsp_document_symbols, bufopts)
vim.keymap.set('n', '<leader>T', builtin.lsp_workspace_symbols, bufopts)
vim.keymap.set('n', '<leader>/', builtin.live_grep, bufopts)
vim.keymap.set('n', '<leader>k', builtin.keymaps, bufopts)
vim.keymap.set('n', '<leader>P', builtin.commands, bufopts)

-- tasks config
telescope.load_extension('tasks')
local tasks = telescope.extensions.tasks

--- You may pass multiple generators at once ( `custom.add({...}, {...}, {...})` )
tasks.generators.custom.add({
    generator = function(buf)
        return {
            'cocos compile',
            cmd = { 'curl', 'http://localhost:7456/update-db' }
        }
    end,
    opts = {
        name = 'cocos',
        filetypes = { 'javascript', 'typescript' },
    }
})
